/*********************************************************************
* File: util.h
*
* \brief Miscellaneous utility functions.
*
* \author Instituto Superior Tecnico de Lisboa, Portugal
* \author Technical University of Lisbon, Portugal
* 
* \author Agentes Autonomos e Sistemas Multiagente
* \author Autonomous Agents and Multiagent Systems
* 
* \version	1.0
* \date		2006/2007
*********************************************************************/
#pragma once

#include "../engine.h"
#include "../game/globals.h"
#include "stringLibrary.h"
using namespace game;

namespace util{
//=============================================================================
// Constants and defines
//=============================================================================
/**  **/
#define NUM_TAGS 22


//=============================================================================
// Enumerations
//=============================================================================
/** Visible body parts **/
class VisibleBodyParts{
public:
	enum Enumeration
	{
		head	= (1 << 0),
		waist	= (1 << 1),
		custom	= (1 << 2)
	};
};

//=============================================================================
// Function prototypes
//=============================================================================
void traceline( 
				   const Vector &vecStart, const Vector &vecEnd, 
				   IGNORE_MONSTERS igmon, IGNORE_GLASS ignoreGlass, 
				   edict_t *pentIgnore, TraceResult *ptr );
void traceline( 
				   const Vector &vecStart, const Vector &vecEnd, 
				   IGNORE_MONSTERS igmon, edict_t *pentIgnore, 
				   TraceResult *ptr );
void traceHull( 
				   const Vector &vecStart, const Vector &vecEnd, 
				   IGNORE_MONSTERS igmon, int hullNumber, edict_t *pentIgnore, 
				   TraceResult *ptr );
void traceModel( 
					const Vector &vecStart, const Vector &vecEnd, 
					int hullNumber, edict_t *pentModel, TraceResult *ptr );
void decalTrace( TraceResult *pTrace, char* pszDecalName );
void drawBeam(edict_t *pEntity, Vector start, Vector end, int width,
        int noise, int red, int green, int blue, int brightness, int speed, int life);
void drawArrow(edict_t *pEntity, Vector start, Vector end, int width,
        int noise, int red, int green, int blue, int brightness, int speed, int life);

bool fBoxVisible(edict_t *pEdict, edict_t *pTargetEdict, Vector *pvHit, unsigned char *ucBodyPart);
bool fVisibleViewCone(Vector &vecOrigin, edict_t *pEdict );
bool fVisible(const Vector &vecOrigin, edict_t *pEdict );
bool fInViewCone(Vector *pOrigin, edict_t *pEdict);
void getBonePosition(edict_t* entity, int bone, Vector* position);
float getShootingConeDeviation(edict_t *pEdict, Vector *pvecPosition);

Vector vecBModelOrigin(edict_t *pEdict);
bool isAlive(edict_t *pEdict);
bool isPlayer(edict_t *pEdict);
bool isHumanPlayer(edict_t *pEdict);
int getNearestPlayerIndex(Vector vecOrigin);
int getHighestFragsBot(int team);
int highestWeaponOfEdict(edict_t *pEdict);
int getAgentIndex(edict_t *pent);
CounterStrikeTeams::Enumeration getTeam(edict_t *pEntity);

bool isReachable(const Vector &v_src, const Vector &v_dest);
bool isShootableBreakable(edict_t *pent);
Vector vecCheckToss( entvars_t *pev, const Vector &vecSpot1, Vector vecSpot2, float flGravityAdj );
Vector vecCheckThrow( 
						 entvars_t *pev, const Vector &vecSpot1, Vector vecSpot2, 
						 float flSpeed, float flGravityAdj );
float getTravelTime(float fMaxSpeed, Vector vecSource, Vector vecPosition);

void fakeClientCommand(edict_t *pFakeClient, const char *fmt, ...);
unsigned short fixedUnsigned16( float value, float scale );
short fixedSigned16( float value, float scale );

bool isNullString(const char *str);
strings::StringNode *getNodeString(strings::StringNode* pNode,int NodeNum);
void trimBlanks(char *in_string, char *out_string);
int chatTrimTag(char *original_name, char *out_name);
void convertNameToHuman(const char *original_name, char *out_name);
void dropCharacter(char *out_string);
void swapCharacter(char *out_string);

const char *getArg(const char *command, int arg_number);
char* varArgs( char *format, ... );
void getGameDirectory(char *mod_name);
void getModDirectory(char *dir);
void getModName(char* name);
void fillBufferFromFile(FILE* fpFile, char *pszBuffer, int file_index);
void createPath(char *path);

void showMenu( edict_t *pEdict, int slots, int displaytime, bool needmore, const char *pText );
void hostPrint(edict_t *pEntity, PRINT_TYPE msg_dest, const char *fmt, ...);
void ClientPrint( 
				 entvars_t *client, int msg_dest, const char *msg_name, 
				 const char *param1, const char *param2, const char *param3, 
				 const char *param4 );
void clientPrintAll( 
						int msg_dest, const char *msg_name, const char *param1, 
						const char *param2, const char *param3, const char *param4 );

void terminateOnError(const char *string);
void freeAllTheStuff(void);
edict_t* findEntityBasedOnOrigin(Vector origin);

//=============================================================================
// Global variables
//=============================================================================
/**  **/
extern bool g_isFakeClientCommand;
/**  **/
extern int g_fakeArgCount;
/**  **/
extern char g_argv[256];
}